// pages/collection/collection.js
import request from '../../utils/request'
Page({

    /**
     * 页面的初始数据
     */
    data: {

        collectionList: [], // 收藏专辑
        collectionSongList:[],
        navState: 0,//导航状态
        userId: Number

    },
      //监听滑块
  bindchange(e) {
    // console.log(e.detail.current)
    let index = e.detail.current;
    this.setData({
      navState: index
    })
  },

  toCollectInfo(e){

    let a =  e;
    console.log(a);
    wx.navigateTo({
        url: '/pages/collectInfo/collectInfo'
      })

},
  //点击导航
  navSwitch: function (e) {
    // console.log(e.currentTarget.dataset.index)
    let index = e.currentTarget.dataset.index;
    this.setData({
      navState: index
    })
  },
  async getCollectionList() {
    let collectionList = await request('/album/sublist');
    
    this.setData({
        collectionList
    })
    console.log(this.data.collectionList)
  },
  //这个方法用来获取收藏歌单
  async getcollectionSongList(id) {
    let collectionSongList = await request('/user/playlist',{uid:id});
    
    this.setData({
      collectionSongList
    })
    console.log(this.data.collectionSongList)
  },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getCollectionList()

        let userInfo = wx.getStorageSync('userInfo');
        
        userInfo = JSON.parse(userInfo)
        let userId = userInfo.userId
        this.setData({
          userId,//当前用户的id
        })
        this.getcollectionSongList(userId)
        console.log(userInfo);
        console.log(userId);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})